﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BSCMFF.Core.DataAccessLayer;
using Telerik.Web.UI;
using BSCMFF.Core;

namespace BSCMFF.Web.Pages.BSC_Setup
{
    public partial class DrillingKPI : MultiLanguagePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                LoadKPIs();
            }
        }

        private void LoadKPIs()
        {
            BSCEntities context = new BSCEntities();

            List<Strategic_Target> sts = (from st in context.Strategic_Target
                                          select st).ToList();

            foreach (Strategic_Target target in sts)
            {
                RadTreeNode stnode = new RadTreeNode();
                stnode.ImageUrl = "~/Images/KPI Drilling/targetIcon.jpg";

                stnode.Text = target.Name;
                stnode.Attributes["Description"] = target.Description;
                stnode.Attributes["NodeType"] = target.GetType().Name;

                RadTreeView1.Nodes.Add(stnode);

                List<Business_Solution> bss = (from bs in context.Business_Solution
                                               where bs.Strategic_Target_FK == target.Strategic_Target_ID
                                               select bs).ToList();

                foreach (Business_Solution solution in bss)
                {
                    RadTreeNode bsnode = new RadTreeNode();
                    bsnode.ImageUrl = "~/Images/KPI Drilling/questionmark.jpg";
                    bsnode.Text = solution.Solution;
                    bsnode.Attributes["Description"] = "";// solution.
                    bsnode.Attributes["NodeType"] = solution.GetType().Name;

                    stnode.Nodes.Add(bsnode);


                    List<KPI> kpis = (from kpi in context.KPIs
                                      where kpi.Solution_FK == solution.ID
                                      select kpi).ToList();

                    foreach (KPI k in kpis)
                    {
                        RadTreeNode node = new RadTreeNode();
                        node.ImageUrl = "~/Images/KPI Drilling/graph Icon.jpg";
                        node.Text = k.Name;
                        //node.Attributes["aPosition"] = "position";
                        node.Attributes["Description"] = k.Description;
                        node.Attributes["NodeType"] = k.GetType().Name;


                        bsnode.Nodes.Add(node);

                        List<Personal_KPI> pkpis = (from pkpi in context.Personal_KPI.Include("User")
                                                    where pkpi.KPI_FK == k.KPI_ID
                                                    select pkpi).ToList();

                        foreach (Personal_KPI pk in pkpis)
                        {
                            RadTreeNode pnode = new RadTreeNode();
                            pnode.ImageUrl = "~/Images/KPI Drilling/icon-person.png";
                            pnode.Text = pk.Name;
                            //pnode.Attributes["aPosition"] = "bposition";
                            pnode.Attributes["Description"] = pk.Description;
                            pnode.Attributes["NodeType"] = pk.GetType().Name;
                            pnode.Attributes["UserID"] = pk.User_FK.ToString();
                            pnode.Attributes["Fullname"] = pk.User.Fullname;
                            node.Nodes.Add(pnode);
                        }
                    }
                }
            }

        }
    
    }
}